let util = require('../../utils/util');

let requestDomain = util.config('requestDomain');

let that;

Page({

  data: {
  
    feedBackContent: '',

    feedBackContact: ''

  },

  onLoad: function (options) {
  
    that = this;

  },

  feedBackContentInput: function(e) {
      that.data.feedBackContent = e.detail.value;
  },

  feedBackContactInput: function(e) {
      that.data.feedBackContact = e.detail.value;
  },

  submitFeedBack: function() {
      wx.showModal({
          title: '确认提交？',
          content: '您将提交此反馈，是否确认提交？',
          success: function(modal) {
            if(modal.confirm) {
                let {feedBackContent, feedBackContact} = that.data;
                wx.showNavigationBarLoading();
                wx.request({
                    url: requestDomain + 'feedBack/add',
                    method: 'POST',
                    data: {
                        storeId: util.globalData('storeId'),
                        _3rdSession: util.globalData('_3rdSession'),
                        feedBackType: 'service',
                        feedBackContent: feedBackContent,
                        feedBackContact: feedBackContact
                    },
                    success: function(result) {
                        wx.hideNavigationBarLoading();
                        if(util.checkSuccess(result) && result.data && result.data.data) {
                            wx.showToast({
                                title: '感谢您的反馈',
                                icon: 'success',
                                mask: true
                            });
                            setTimeout(function() {
                                wx.navigateBack();
                            }, 600);
                        }
                        else {
                            util.showError('提交失败', '非常抱歉，您的反馈提交时出现错误' + result.data.errMsg, result.data.errCode);
                        }
                    },
                    fail: function() {
                        wx.hideNavigationBarLoading();
                        util.showError('提交失败', '非常抱歉，提交您的反馈时失败');
                    }
                })
            }
          }
      });
  }
  
})